{include file="header/index" /}
<div class="newContentBox">
    <!-- 分割部分 -->
    <div class="newListPart">
<!--        <div class="newTitleBox">-->
<!--            <span class="layui-inline newListTitle">市场推广提现申请列表</span>-->
<!--        </div>-->
        <form method="get" name="searchuser" action="#" class="layui-form">
            <div class="newForm">
                <div class="newGroup">
                    <div class="newGroupInput">
                        <input type="text" value="" id="keyword" placeholder="请输入申请编号|姓名|手机号" class="layui-input-search cover_layui_i"/>
                    </div>
                </div>
                <div class="newGroup newBtnBox">
                    <a id="search" class="newBtnSearch newBtnPrimary">搜索</a>
                </div>

            </div>
        </form>
        <div class="newTableBox">
            <table class="layui-table" lay-filter="changeTable">
                <thead>
                <tr>
                    <th lay-data="{field: 'cash_order_number',width: 200}">申请编号</th>
                    <th lay-data="{field: 'workers_name',width: 100}">姓名</th>
                    <th lay-data="{field: 'workers_phone',width: 120}">手机号</th>
                    <th lay-data="{field: 'cash_order_money',width: 80}">申请积分</th>
                    <th lay-data="{field: 'remit_money',width: 80}">打款积分</th>
                    <th lay-data="{field: 'payment_fee',width: 80}">手续费</th>
                    <th lay-data="{field: 'balance',width: 80}">账户积分</th>
                    <th lay-data="{field: 'bank_number',width: 200}">收款账户</th>
                    <th lay-data="{field: 'cash_order_state_name',width: 80}">申请状态</th>
                    <th lay-data="{field: 'add_time',width: 150}">申请时间</th>
                    <th lay-data="{field: 'examine_pass',width: 150}">审核时间</th>
                    <th lay-data="{field: 'play_money_state_name',width: 80}">打款状态</th>
                    <th lay-data="{field: 'bank_note',minWidth: 100}">打款备注</th>
                    <th lay-data="{field: 'remarks',minWidth: 100}">系统备注</th>
                    <th lay-data="{field: 'error_msg',minWidth: 100}">错误信息</th>
                    <th lay-data="{field: 'operation',minWidth:200,fixed: 'right'}" class="newOperation">操作</th>
                </tr>
                </thead>
                <!--套数据 laypage-->
                <script id="list-template" type="text/html">
                    {{# for(var i=0;i<d.length;i++){  }}
                    <tr>
                        <td>{{d[i].cash_order_number}}</td>
                        <td>{{d[i].workers_name||'--'}}</td>
                        <td>{{d[i].workers_phone||'--'}}</td>
                        <td>{{d[i].cash_order_money}}</td>
                        <td>{{d[i].remit_money}}</td>
                        <td>{{d[i].payment_fee}}</td>
                        <td>{{d[i].balance}}</td>
                        {{# if(d[i].account_type == 1){ }}
                        <td>{{d[i].bank_name}}(卡号:{{d[i].bank_number}})</td>
                        {{# }else{ }}
                        <td>微信零钱(手机号:{{d[i].phone}})</td>
                        {{# } }}
                        <td>{{d[i].cash_order_state_name}}</td>
                        <td>{{d[i].add_time}}</td>
                        <td>{{d[i].examine_pass||'--'}}</td>
                        <td>{{d[i].play_money_state_name}}</td>
                        <td>{{d[i].bank_note||'--'}}</td>
                        <td>{{d[i].remarks||'--'}}</td>
                        <td>{{d[i].error_msg||'--'}}</td>
                        <td class="newOperation">
                            {{# if(d[i].cash_order_state == 1){ }}
                            <a class="layui-btn newBtnDefault" onclick="Auditing({{d[i].cash_order_id}},1)">通过</a>
                            <a class="layui-btn newBtnDefault newBtnGreen" onclick="Auditing({{d[i].cash_order_id}},2)">拒绝</a>
                            {{# } }}
                            {{# if(d[i].cash_order_state == 2){ }}
                            <a class="layui-btn newBtnDefault" onclick="queryBank({{d[i].cash_order_id}},1)">查询</a>
                            {{# } }}
                        </td>
                    </tr>
                    {{# } }}
                </script>
                <tbody id="list-content"></tbody>
            </table>
            <!--用来存当前页码数-->
            <input type="hidden" value="1" id="curr_" />
            <div class="laypage">
                <div class="laypage_total">共<span id="total_number"></span>条数据&nbsp;&nbsp;<span id="allpage"></span></div>
                <div class="laypage_skip" id="AjaxPage"></div>
            </div>
        </div>

    </div>

</div>

<script>
    var layer = layui.layer,
        element = layui.element,
        laydate = layui.laydate,
        laypage = layui.laypage,
        form = layui.form,
        laytpl = layui.laytpl,
        table = layui.table;
    $.ajaxSetup({headers: {token: $.cookie('token'),company: $.cookie('company_id')}});;


    function queryBank(id) {
        var request_data = {};
        request_data.id = id;
        request_data.source = 1;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Withdraw/queryBank", request_data, function(data){
            Ajaxpage();
            if (data.code < 0){
                top.layer.msg(data.message,{icon:2,time:2500,shade: 0.1,});
                return false;
            }
            top.layer.msg(data.message,{icon:1,time:1500,shade: 0.1,});

        });
    }

    /**
     * 审核操作
     * @param id    申请ID
     * @param t     类型
     * @constructor
     */
    function Auditing(id,t) {
        var play_money_type = 1;
        var bank_note = '';
        var note = '';
        var html = '';
        html +='<form class="layui-form popBox" action="" method="post">';
        if (t == 1){
            html +='<div class="popChoose">';
            html +='<div class="leftPop">打款类型：</div>';
            html +='<div class="rightPop">';
            html +='<div class="selectBox">';
            html +='<select id="user_class" name="user_class" class="layui-input cover_layui_i" lay-filter="aihao">';
            html +='<option value="1">线上打款</option>';
            html +='<option value="0">线下打款</option>';
            html +='</select>';
            html +='</div>';
            html +='</div>';
            html +='</div>';
            html +='<div class="popChoose">';
            html +='<div class="leftPop">打款备注：</div>';
            html +='<div class="rightPop">';
            html +='<textarea placeholder="请输入到账时备注(最多40字符)" class="layui-textarea" id="remarks1" maxlength="40"></textarea>';
            html +='</div>';
            html +='</div>';
            html +='<div class="popChoose">';
            html +='<div class="leftPop">系统备注：</div>';
            html +='<div class="rightPop">';
            html +='<textarea placeholder="请输入系统备注(提现人不可见)" class="layui-textarea" id="remarks2"></textarea>';
            html +='</div>';
            html +='</div>';
        } else {
            html +='<div class="popChoose">';
            html +='<div class="leftPop">拒绝理由：</div>';
            html +='<div class="rightPop">';
            html +='<textarea placeholder="请输入拒绝理由" class="layui-textarea" id="remarks2"></textarea>';
            html +='</div>';
            html +='</div>';
        }
        html +='</form>';
        parent.layer.open({
            title:'审核',
            type: 1,
            area: ['650px', '450px'], //宽高
            shadeClose: false, //点击遮罩关闭
            content: html,
            btn: ['确认', '取消'],
            btnAlign: 'c',
            success: function(layero, index){
                parent.form.render();
            }
            ,yes: function(index, layero){
                play_money_type = $(layero).find("#user_class").val();
                bank_note = $(layero).find("#remarks1").val();
                note = $(layero).find("#remarks2").val();
                review(id,t,bank_note,note,play_money_type);
                // return true;
                parent.layer.close(index);
            }
            ,btn2: function(index, layero) {
                //按钮【按钮二】的回调
                // return false;//开启该代码可禁止点击该按钮关闭
                return true;
            }
            ,cancel: function(){
                //右上角关闭回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    }

    /**
     * 处理审核
     * @param id                申请ID
     * @param t                 审核状态
     * @param bank_note         打款备注
     * @param note              备注
     * @param play_money_type   打款类型
     */
    function review(id,t,bank_note,note,play_money_type) {
        var request_data = {};
        request_data.id = id;
        request_data.play_money_type = play_money_type;
        request_data.type = 1;
        request_data.status = t;
        request_data.bank_note = bank_note;//打款备注,收款人接收提示
        request_data.note = note;//备注
        console.log(request_data);
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Withdraw/review", request_data, function(data){
            Ajaxpage();
            if (data.code < 0){
                top.layer.msg(data.message,{icon:2,time:2500,shade: 0.1,});
                return false;
            }
            top.layer.msg(data.message,{icon:1,time:1500,shade: 0.1,});

        });
    }

    Ajaxpage();
    function Ajaxpage(curr){
        var loadingFlag= layer.msg('正在读取数据，请稍候……', { icon: 16, shade: 0.01,shadeClose:false,time:60000 });
        $("#curr_").val(curr);
        var keyword = $('#keyword').val();
        var request_data = {};
        request_data.keyword = keyword;
        request_data.page = curr || 1;
        request_data.role = 6;
        request_data = JSON.stringify(request_data);
        $.post("{:config('api')}/Achievement/Withdraw/dealerWithdraw", request_data, function(data){
            layer.close(loadingFlag);
            var page = data.data.page;
            $("#total_number").text(page.total_number);
            data = data.data.data;
            if(data==''){
                $("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
            }else{
                var tpl = document.getElementById('list-template').innerHTML;
                laytpl(tpl).render(data, function(html){
                    document.getElementById('list-content').innerHTML = html;
                });

            }
            table.init('changeTable');
            //分页
            laypage.render({
                elem: 'AjaxPage' //分页容器的id
                ,count: page.total_number //总条数
                ,limit: page.row //每页条数
                ,skin: '#1AB5B7' //自定义选中色值
                ,curr: curr || 1
                ,layout: [ 'prev', 'page', 'next', 'skip']
                //,skip: true //开启跳页
                ,jump: function(obj, first){
                    if(!first){
                        Ajaxpage(obj.curr)
                    }
                    $('#allpage').html('第'+ obj.curr +'页，共'+ page.total_page +'页');
                }
            });
        });
    }
    // 搜索表单
    $("#search").click(function () {
        Ajaxpage(1);
    });
    // 编辑
    function editConfig(id) {
        window.location.href = "{:url('Configure/edit')}?id=" + id;
    }
    // 删除
    function delConfig(id) {
        layer.confirm('确认删除此条记录？', function(index){
            //do something
            var index = layer.load(1, {
                shade: [0.1,'#fff'] //0.1透明度的白色背景
            });
            var data = {};
            data.id = id;
            data = JSON.stringify(data);
            $.post("{:config('api')}/Achievement/Config/delConfig",data,function (flag) {
                layer.close(index);
                if (flag.code < 0){
                    layer.msg(flag.message,{icon:2,time:1500,shade: 0.1,});
                    return false;
                }
                Ajaxpage();
                layer.msg(flag.message,{icon:1,time:1500,shade: 0.1,});
            });

            layer.close(index);
        });
    }
</script>
